module.exports = function (app, mongoose) {
  app.post("/staff/create", function (req, res) {
    var Staff = mongoose.model("Staff");
    var staffList = new Staff(
      req.body
    );
    Staff.find({
      staffName: req.body.staffName,
      sex: req.body.sex,
      phone: req.body.phone,
    }, function (err, docs) {
      console.log(docs)
      if (err) {
        console.log("err:", err);
        res.json({
          state: 0,
          msg: "数据库错误"
        });
      } else {
        if (docs == "") {
          staffList.save(function (err) {
            // 执行保存，并查看返回情况
            if (err) {
              console.log(err);
            } else {
              res.json({
                status: 1,
                msg: "录入成功"
              });
              return
            }
          });
        } else {
          res.json({
            status: 0,
            msg: "已有此员工信息"
          });
          return
        }
      }
    })
  });
}
